%this includes the weights of the nodes into consideration before deciding
%on a path

clc;
clear all;

N1 = 11;
N1wt = 1;

v = [1 2 3 4 5 6 7];
M = 7;
u = perms(v);
u8 = [u u(:,1)];

N = 100000;

A = [0 N1 N1 N1 N1 N1 N1;
    N1  0 12  N  N  9 16;
    N1 12  0 19 12  N 15;
    N1  N 19  0 21  N 17; 
    N1  N 12 21  0 10 16;
    N1  9  N  N 10  0 10;
    N1 16 15 17 16 10  0];

%weights
q = [N1wt 1 1 1 1 1 1];

qleft = sum(q);
for i=1:length(u8(:,1))
    s(i) = 0;    
    qdone = 0;
    for j=1:M 
        qdone = qdone + q(u8(i,j));
        index1 = u8(i,j);
        index2 = u8(i,j+1);
        multiplier = A(u8(i,j),u8(i,j+1));
        multiplied = (qleft-(qdone-q(u8(i,1))));
        s(i) = s(i) + (qleft-(qdone-q(u8(i,1))))*A(u8(i,j),u8(i,j+1));
    end
end
[smin,sminindex] = min(s(factorial(M)-factorial(M-1)+1:factorial(M)));
smin

temp = s(factorial(M)-factorial(M-1)+1:factorial(M));
tempindex = find(s(factorial(M)-factorial(M-1)+1:factorial(M))==smin*ones(1,factorial(M-1)))
sequence = u8(factorial(M)-factorial(M-1)+tempindex,:)